﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GameDataTempshitEditor
{
    public partial class EnvSetup : Form
    {
        public EnvSetup()
        {
            InitializeComponent();

            this.Load += EnvSetup_Load;
            button5.Click += button5_Click;
            textBox1.TextChanged += DataChanged;
            textBox2.TextChanged += DataChanged;
        }

        void button5_Click(object sender, EventArgs e)
        {
            if (!ValidateSettings())
                return;

            Properties.Settings.Default.ReflectionPath = textBox1.Text;
            Properties.Settings.Default.DataPath = textBox2.Text;
            Properties.Settings.Default.CookerPath = textBox3.Text;
            Properties.Settings.Default.OutputPath = textBox4.Text;
            Properties.Settings.Default.SkipSettings = checkBox1.Checked;
            Properties.Settings.Default.DepotPath = textBox5.Text;
            Properties.Settings.Default.Save();

            this.DialogResult = DialogResult.OK;
        }

        void DataChanged(object sender, EventArgs e)
        {
            button5.Enabled = ValidateSettings();
        }

        bool ValidateSettings()
        {
            if (textBox1.Text == "")
                return false;

            if (textBox2.Text == "")
                return false;

            return true;
        }

        void EnvSetup_Load(object sender, EventArgs e)
        {
            // load settings
            textBox1.Text = Properties.Settings.Default.ReflectionPath;
            textBox2.Text = Properties.Settings.Default.DataPath;
            textBox3.Text = Properties.Settings.Default.CookerPath;
            textBox4.Text = Properties.Settings.Default.OutputPath;
            textBox5.Text = Properties.Settings.Default.DepotPath;
            checkBox1.Checked = Properties.Settings.Default.SkipSettings;
        }

        public static bool ShowSetup()
        {
            var dlg = new EnvSetup();
            return (dlg.ShowDialog() == DialogResult.OK);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            folderBrowserDialog1.Description = label2.Text;
            folderBrowserDialog1.SelectedPath = textBox1.Text;
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.Description = label3.Text;
            folderBrowserDialog1.SelectedPath = textBox2.Text;
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox2.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = label4.Text;
            openFileDialog1.FileName = textBox3.Text;
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox3.Text = openFileDialog1.FileName;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Title = label5.Text;
            saveFileDialog1.FileName = textBox4.Text;
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox4.Text = saveFileDialog1.FileName;
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.Description = label6.Text;
            folderBrowserDialog1.SelectedPath = textBox5.Text;
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox5.Text = folderBrowserDialog1.SelectedPath;
            }
        }
    }
}

